home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-04-05 | 1.4 KB | 57 lines | [TEXT/CWIE] |
- import java.applet.*;
- import java.awt.*;
- import java.net.*;
-
- public class popup extends Applet
- {
- private Choice urlChoices;
- int numURLs;
-
- public void init()
- {
- this.setBackground( Color.yellow );//java.awt.Color
- this.setForeground( Color.red );//java.awt.Color
-
- urlChoices = new Choice();
-
- urlChoices.addItem( "www.metrowerks.com" );
- urlChoices.addItem( "www.netscape.com" );
- urlChoices.addItem( "www.mactech.com" );
-
- urlChoices.setForeground( Color.green );
- urlChoices.setBackground( Color.blue );
-
- this.add( new Label( "Select URL: " ) );
- this.add( urlChoices );
- }
-
- public boolean action( Event e, Object obj )
- {
- URL url;
-
- if ( e.target == urlChoices )
- {
- try
- {
- url = new URL( obj.toString() );
- }
- catch( MalformedURLException err )
- {
- // Could print error message here.
- return true;
- }
- /* If a method throws an exception, you must be prepared to catch it,
- even if you ignore the result. See java.net.URL().
- If I throw an exception, I'll create a new java.lang.exception
- object (or some class that extends throwable). But if I catch an
- exception, the exception object will be passed to me, just like err was here.
- Take a look at Throwable to see what you can do with err (especially getMessage()).
-
- */
- this.getAppletContext().showDocument( url );
- return true;
- }
- else
- return super.action( e, obj );
- }
- }